﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PMS.Model;
using PMS.DBUtility;

namespace PMS.DAL
{
    public class DdDAL
    {
        private readonly string strsql = "INSERT INTO P_DD (Name,Model,Shelf,Price,NamePY,CategoryId,Numbers) values(?,?,?,?,?,?,?)";
        private readonly string strsql2 = "Select * from P_DD where Name=? and Model=? and Shelf=? and Price = ?";
        public bool Exists(string name,string model,string shelf,double price)
        {
            System.Data.OleDb.OleDbParameter[] paramters = new System.Data.OleDb.OleDbParameter[4];
            paramters[0] = new System.Data.OleDb.OleDbParameter("?", name);
            paramters[1] = new System.Data.OleDb.OleDbParameter("?", model);
            paramters[2] = new System.Data.OleDb.OleDbParameter("?", shelf);
            paramters[3] = new System.Data.OleDb.OleDbParameter("?", price);
            return Convert.ToBoolean(SQLHelper.Execute(strsql2, paramters));            
        }

        public bool Exists(string numbers)
        {
            bool state = false;
            //TODO
            return state;
        }

        public bool Insert(DDinfo ddinfo)
        {
            if (Exists(ddinfo.Name,ddinfo.Model,ddinfo.Shelf,ddinfo.Price))
            {
                // TODO
                return false;
            }
            System.Data.OleDb.OleDbParameter[] paramters = new System.Data.OleDb.OleDbParameter[7];            
            paramters[0] = new System.Data.OleDb.OleDbParameter("?", ddinfo.Name
);
            paramters[1] = new System.Data.OleDb.OleDbParameter("?", ddinfo.Model);
            paramters[2] = new System.Data.OleDb.OleDbParameter("?", ddinfo.Shelf);
            paramters[3] = new System.Data.OleDb.OleDbParameter("?", ddinfo.Price);
            paramters[4] = new System.Data.OleDb.OleDbParameter("?", ddinfo.NamePY);
            paramters[5] = new System.Data.OleDb.OleDbParameter("?", ddinfo.CategoryId);
            paramters[6] = new System.Data.OleDb.OleDbParameter("?", ddinfo.Numbers);
            return Convert.ToBoolean(SQLHelper.Execute(strsql, paramters));

        }

        public bool Delete(string numbers)
        {
            bool state = false;
            //TODO
            state = true;

            return state;
            
        }
        public bool Update(string id,DDinfo ddinfo)
        {
            bool state = false;
            //TODO
            state = true;
            return state;

        }
        public DDinfo GetDDinfo(string id)
        {
            DDinfo ddinof = new DDinfo();
            return ddinof;
        }
        public IList<DDinfo> GetList()
        {
            List<DDinfo> ddinfolist = new List<DDinfo>();
            DDinfo ddinfo = new DDinfo();
            ddinfolist.Add(ddinfo);
            //TODO
            return ddinfolist;

        }
    }
}
